package cn.com.roy.thread.t6_2.singleton_2_2;

public class MyObject {
    private static MyObject myObject;

    private MyObject() {
    }

    //同步代码块效率一样底下
     public static MyObject getInstance() {
        try {
            synchronized (MyObject.class) {
                if (myObject == null) {
                    Thread.sleep(3000);
                    myObject = new MyObject();
                }
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return myObject;
    }
}
